﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MINERP.DAL;
using MINERP.DAL.InfoConfig;

namespace MINERP.BLL.InfoConfig
{
    public class UserRoleBLL
    {
        #region Private Fields
        private List<tb_Power> _powerList = null;

        #endregion


        #region Public Properties
        public List<tb_Power> PowerList
        {
            get
            {
                return _powerList;
            }
        }

        #endregion


        #region Public Methods
        /// <summary>
        /// 获得单个节点对象
        /// </summary>
        /// <param name="techName"></param>
        /// <returns></returns>
        public tb_Tech GetTechObj(string techName)
        {
            return UserRoleDAL.GetTechObj(techName);
        }
        /// <summary>
        /// 获得单个角色能查看的节点
        /// </summary>
        /// <param name="powerName"></param>
        /// <returns></returns>
        public tb_Power GetPowerAndTech(string powerName)
        {
            return UserRoleDAL.GetPowerAndTech(powerName);
        }
        /// <summary>
        /// 获得角色List
        /// </summary>
        public void GetPowerList()
        {
            _powerList = UserRoleDAL.GetPowerList();
        }

        public List<tb_Power> GetRoleList()
        {
            return UserRoleDAL.GetPowerList();
        }
        /// <summary>
        /// 获得节点List
        /// </summary>
        /// <returns></returns>
        public List<tb_Tech> GetTechList()
        {
            return UserRoleDAL.GetTechList();
        }

        public tb_Power GetPowerObj(string name)
        {
            return UserRoleDAL.GetPowerObj(name);
        }
        /// <summary>
        ///  添加角色
        /// </summary>
        /// <param name="power"></param>
        public void AddRole(tb_Power power)
        {
            UserRoleDAL.AddRole(power);
        }
        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="power"></param>
        /// <param name="techList"></param>
        public void UpdateRole(tb_Power power, List<tb_Tech> techList)
        {
            UserRoleDAL.UpdateRole(power, techList);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="power"></param>
        public void DeleteRole(tb_Power power)
        {
            using (newSampleYPDBEntities entity = new newSampleYPDBEntities())
            {
                tb_Power pow = entity.tb_Power.FirstOrDefault(p=>p.PowerId ==power.PowerId);
                entity.DeleteObject(pow);
                entity.SaveChanges();
            }
            //UserRoleDAL.DeleteRole(power);
        }
        #endregion
    }
}
